package com.guangyuan.network.dao.jdbc.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.guangyuan.network.constants.SqlType;
import com.guangyuan.network.dao.interfaces.ProductGroupDao;
import com.guangyuan.network.dao.interfaces.sql.ProductGroupSql;
import com.guangyuan.network.dataobject.ProductGroup;
import com.guangyuan.network.datasource.pool.util.ConnectionUtil;

public class ProductGroupDaoImp implements ProductGroupDao {

	private static Logger logger = Logger.getLogger(ProductGroupDaoImp.class);

	public void addProductGroup(ProductGroup productGroup) {
		// TODO Auto-generated method stub

	}

	public void deleteProductGroup(ProductGroup productGroup) {
		// TODO Auto-generated method stub

	}

	public void updateProductGroup(ProductGroup productGroup) {
		// TODO Auto-generated method stub

	}
	//用户必须保证提交的sql和参数的个数对应起来
	@Override
	public Object executeSql(Connection conn, String sql, Object[] parameters, SqlType type) {

		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try {
			pstmt = ConnectionUtil.getStatement(conn, sql, type);
			if (null != parameters) {
				for (int i = 0; i < parameters.length; i++) {
					pstmt.setObject(i + 1, parameters[i]);
				}
			}
			if (pstmt.execute()) {
				rs = pstmt.getResultSet();
			} else {
				return pstmt.getUpdateCount();
			}
			
			if(SqlType.INSERT.equals(type)) {
				return pstmt.getGeneratedKeys();
			}
		} catch (SQLException e) {
			logger.error(e.getMessage());
		}
		
		return rs;
	}

}
